package com.hs.excel.demos.listenter;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.hs.excel.demos.pojo.RequestParm;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Slf4j
public class Test extends AnalysisEventListener<Map<String, String>> {

    private RequestParm requestParm;
    private Map<Integer, String> head;

    private StringBuffer  stringBuffer;

    private  List<String> valuess = new ArrayList<>();

    public Test(RequestParm a) {
        this.requestParm = a;
    }
/// 查询语句 in（‘）
    @Override
    public void invoke(Map<String, String> data, AnalysisContext analysisContext) {
        List<String> values = new ArrayList<>(data.values());
        valuess.add(values.get(0));
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        StringBuffer  stringBuffer = new StringBuffer("select * from" + requestParm.getTableName() + " where  CODE IN");
        stringBuffer.append("(");
        for (String filed : valuess) {
            stringBuffer.append("'").append(filed).append("',");
        }
        stringBuffer.deleteCharAt(stringBuffer.length() - 1);
        stringBuffer.append("); ");
        log.info("{}",stringBuffer);
    }





    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        this.head = headMap;
    }

    //批量插入
    private void entiretyMysqlhandle(Map<String, String> data) {
        //单条
        List<String> values = new ArrayList<>(data.values());

        StringBuffer  stringBuffer = new StringBuffer("(");
        for (String filed : values) {
            if (filed == null) {
                String s = "'',";
                stringBuffer.append(s);
            } else {
                String s = "'" + filed + "'" + ",";
                stringBuffer.append(s);
            }
        }
        stringBuffer.deleteCharAt(stringBuffer.length() - 1);
        stringBuffer.append("),");
        Comont.insertList.add(stringBuffer.toString());
    }




}
